import Vue from 'vue'
import { createStore } from 'vuex'
import { dynamicRoutes } from '../router/router'
import menu from './menu'

export default createStore({
    // 声明变量
    state: {
      isCollapsed: true,
      tabList: [],
      routes: [],
    },
    mutations: {
        UPDATE_COLLAPSED(state, stat) {
            state.isCollapsed = stat
        },
        SET_ROUTES(state, routes) {
            state.routes = routes
        }
    },
    actions: {
        generateRoutes({commit}) {
            return new Promise(resolve => {
                const routesCloner = Object.assign({},dynamicRoutes.find(item => item.name === 'dynamic'))
                routesCloner.children = routesCloner.children.concat(menu.menuLst)
                commit('SET_ROUTES', routesCloner.children)
                resolve(routesCloner)
            })
        }
    }
});